extends Spatial

onready var lstLevels: ItemList = $Panel/VBoxContainer/ItemList
onready var panel: Control = $Panel

var level: Spatial = null

const levels = [
	"res://levels/DefaultLevel1.tscn",
	"res://levels/lvltest07.tscn",
]

func _ready():
	for lev in levels:
		lstLevels.add_item(lev)

func _on_ItemList_item_activated(index):
	if index >= 0 and index < levels.size():
		var ps: PackedScene = load(levels[index])
		if ps != null:
			var lev: Spatial = ps.instance()
			if lev != null:
				if level != null:
					level.queue_free()
					level = null
				add_child(lev)
				level = lev
				panel.hide()

func _unhandled_input(event):
	if event.is_action_pressed("ui_cancel"):
		panel.visible = not panel.visible
